package com.pineapple.module.core.user.service;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import com.pineapple.module.core.user.domain.User;
import com.pineapple.module.core.user.domain.UserCriteria;
import com.pineapple.module.core.user.domain.UserModel;
import com.pineapple.module.core.user.domain.UserSearch;

public class UserManager {
	UserDAO dao = null;

	public UserManager(){
		dao = new UserDAO();
	}

	public List<UserSearch> search(UserCriteria criteria,Connection conn)throws Exception{
		List<UserSearch> lstUser = new ArrayList<UserSearch>();
		int totalRacord =dao.count(criteria, conn);
		criteria.setTotalResult(totalRacord+30);
		criteria.setStart(criteria.getStart() - criteria.getLinePerPage());
			if(totalRacord>0){
				lstUser = dao.search(criteria, conn);
		}
		return lstUser;
	}

	public void add(Connection conn,User user)throws Exception{
		dao.add(conn, user);
	}
	public void edit(Connection conn,User user)throws Exception{
		dao.edit(conn, user);
	}
	public void delete(Connection conn,String userIds)throws Exception{
		dao.delete(conn, userIds);
	}
	public User searchById(Connection conn,int id)throws Exception{
		return dao.searchById(conn, id);
	}

}
